﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using System.Data;

namespace AcessoDados
{
    public class UsuarioDAO:IDisposable
    {
        SqlConnection conexao = null;
        public bool login(Negocio.Usuario usuario)
        {
            conexao = new ConnectionFactory().criaConexao();
            SqlCommand command = new SqlCommand();
            command.Connection = conexao;            
            command.CommandType = System.Data.CommandType.Text;
            command.CommandText = @"SELECT TOP 1 USULOGIN FROM USUARIOS
                                    WHERE LTrim(RTrim(USULOGIN)) = @USULOGIN AND LTrim(RTrim(USUPASSWORD)) = @USUPASSWORD";
            command.Parameters.Add(new SqlParameter("@USULOGIN",usuario.UsuLogin));
            command.Parameters.Add(new SqlParameter("@USUPASSWORD", usuario.UsuPassword));
            SqlDataAdapter sdAdapter = new SqlDataAdapter(command);
            DataTable dt = new DataTable();
            sdAdapter.Fill(dt);
            return (dt.Rows.Count == 1);
                
        }

        public void Dispose()
        {
            if (conexao != null)
            {
                conexao.Close();
                conexao.Dispose();
            }
        }
    }
}
